﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SRB.Tg.Model
{
    public enum eHookAngle
    {
        None = 0, A90 = 90, A135 = 135, A180 = 180,
    }
    public enum eRebarDia
    {
        None = 0,
        D6 = 6,
        D8 = 8,
        D10 = 10,
        D12 = 12,
        D14 = 14,
        D16 = 16,
        D18 = 18,
        D20 = 20,
        D22 = 22,
        D25 = 25,
        D28 = 28,
        D32 = 32,
        D36 = 36,
        D40 = 40,        
    }

    


    public class RebarBend
    {
        //public eRebarDia Diameter;
        public double Degree;

        public RebarBend(double degree)
        {
            //Diameter = diameter;
            Degree = degree;
        }

        public static RebarBend B90
        {
            get
            {
                return new RebarBend(90);
            }
        }

        /// <summary>
        /// 折减值，单位mm，绝对值.
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public double SubtractLength(int d)
        {
            if (Degree<90)
            {
                return (21 * d * Math.Tan(Degree / 180 * Math.PI * 0.5) - 0.18326 * d * Degree);
            }
            else if (Degree==90)
            {
                return Math.Abs(RebarEnd.En90.AddLength(d) - 13 * d);
            }
            else
            {
                return Math.Abs(RebarEnd.En90.AddLength(d) - 13 * d);
            }
        }

    }


    public class RebarEnd
    {
        public eHookAngle HookAngle;
        public int TimeFactor;


        public RebarEnd(eHookAngle ang, int factor)
        {
            HookAngle = ang;
            TimeFactor = factor;
            //Diameter = dia;
        }

        /// <summary>
        /// 弯钩增长值，单位mm
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public double AddLength(int d)
        {
            //int d = Convert.ToInt32(Diameter);
            switch (HookAngle)
            {
                case eHookAngle.None:
                    return 0.0;
                case eHookAngle.A90:
                    return (Math.PI * 3 * d) * 0.5 + TimeFactor * d - 3 * d;
                case eHookAngle.A135:
                    return Math.PI * 3 * d / 180 * 135 + TimeFactor * d;
                case eHookAngle.A180:
                    return Math.PI * 1.75 * d + TimeFactor * d - 1.75 * d;
                default:
                    return 0.0;
            }
        }

        public static RebarEnd En90
        {
            get
            {
                RebarEnd rn = new RebarEnd(eHookAngle.A90, 10);
                return rn;
            }
        }

        public static RebarEnd En135
        {
            get
            {
                RebarEnd rn = new RebarEnd(eHookAngle.A135, 5);
                return rn;
            }
        }

        public static RebarEnd En180
        {
            get
            {
                RebarEnd rn = new RebarEnd(eHookAngle.A180, 3);
                return rn;
            }
        }

        public static RebarEnd NoneHook
        {
            get
            {
                RebarEnd rn = new RebarEnd(eHookAngle.None, 0);
                return rn;
            }
        }

    }
}
